package cn.book.book.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author oldliu
 * @since 1.0
 */
//@Data
//@NoArgsConstructor
//@AllArgsConstructor
    //返回结果准备
public class AjaxResult implements Serializable {
    private String msg;
    private int code=200;//200表示正常，401表示没有登录，405缺少参数，500内部错误
    private Object data;

    public AjaxResult() {
    }

    public AjaxResult(String msg, int code, Object data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public static AjaxResult success(String msg){
        return new AjaxResult(msg,200,null);
    }
    public static AjaxResult success(Object m){
        return new AjaxResult(null,200,m);
    }
    public static AjaxResult success(String msg,Object m){
        return new AjaxResult(msg,200,m);
    }
    public static AjaxResult error(int code,String msg){
        return new AjaxResult(msg,code,null);
    }
    public static AjaxResult error(String msg){
        return new AjaxResult(msg,500,null);
    }

    public static AjaxResult toAjax(int add) {
        if(add>0){
            return success("操作成功");
        }
        return error("操作失败");
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
